<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<h2>Sa-Token SSO-Server 服务端（前后端分离版）</h2>
<input type="text" placeholder="请输入账号" id="name" value="sa">
<input type="password" placeholder="请输入密码" id="pwd" value="123456">
<input type="button" value="登录" id="login">


<script src="https://unpkg.zhimg.com/jquery@3.4.1/dist/jquery.min.js"></script>
<script type="text/javascript">

    // 后端接口地址
    var baseUrl = "http://localhost:8800/sso-server";

    $(function () {
        $("#login").click(function () {
            // 查询当前会话是否登录
            $.ajax({
                url: baseUrl + '/login',
                type: "post",
                data: {
                    name: $("#name").val(),
                    password: $("#pwd").val(),
                },
                dataType: 'json',
                success: function (res) {
                    if (res.code != 200) {
                        alert(res.msg);
                    } else {
                        var back = getParam();
                        console.log(decodeURIComponent(back))
                        location.href = decodeURIComponent(back);
                    }
                },
                error: function (xhr, type, errorThrown) {
                    return alert("异常：" + JSON.stringify(xhr));
                }
            });
        })
    })

    // 从url中查询到指定名称的参数值
    function getParam() {
        var query = window.location.search.substring(1);
        var back = query.substring(9);

        return back ? back : '/';
    }

</script>
</body>
</html>